package com.rfs.suanfa;

/**
 * @author renfushuai
 * @date 2022/2/8
 */
public class 合并两个有序链表 {
    public ListNode mergeTwoLists(ListNode list1, ListNode list2) {
        ListNode mergeList = new ListNode(0);
        ListNode curr=mergeList;
        while (list1 != null && list2 != null) {
            if (list1.val <= list2.val) {
                curr.next=list1;
                curr=curr.next;
                list1 = list1.next;
            }else {
                curr.next=list1;
                curr=curr.next;
                list2 = list2.next;
            }
        }
        if (list1==null){
            curr.next=list2;
        }
        if (list2==null){
            curr.next=list1;
        }
        return mergeList;
    }
}
